<template>
    <div class="timeindex">
        <h2 class="tit">平台时限配置</h2>
        <Form :model="formItem"  label-position="left">
            <div class = 'main'>
                <p class="title">基本信息</p>
                <Row class="box">
                    <Col span="8">
                        <Row :gutter='16'>
                            <Col span="16">
                                <FormItem label="药师审核时限：" >
                                    <InputNumber :min="1" :max="999" v-model="formItem.value1" class="input"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="2">
                                <small>分钟</small>
                            </Col>
                            <Col span="20">
                                <span class="span">说明：如果药师接收处方后，超过此时限还没有审核完处方，则系统自动将处方状态由"审核中"更新为"待审核"状态。</span>
                            </Col>
                        </Row>
                    </Col>
                    <Col span="8">
                        <Row :gutter='16'>
                            <Col span="16">
                                <FormItem label="患者支付时限：">
                                    <InputNumber :min="1" :max="999" v-model="formItem.value2" class="input"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="2">
                                <small>小时</small>
                            </Col>
                            <Col span=20>
                                <span class="span">说明：处方审核通过后，如果患者超过此时限还没有支付，则处方自动失效。</span>
                            </Col>
                        </Row>
                    </Col>
                    <Col span="8">
                        <Row :gutter='16'>
                            <Col span="17">
                                <FormItem label="患者确认收货时限：">
                                    <InputNumber :min="1" :max="999" v-model="formItem.value3" class="input"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="2">
                                <small>小时</small>
                            </Col>
                            <Col span="20">
                                <span class="span">说明：药品送达后，如果患者超过此时限还没有点击【确认收货】，则处方订单自动更新为完成状态。</span>
                            </Col>
                        </Row>
                    </Col>
                </Row>
            </div>
            <div class="buttonbox">
                <Button type="primary" @click="submit(formItem)" :disabled='disabledSave'>
                    <Icon type="ios-checkmark icon" />保存
                </Button>
                <Button type="primary" @click="wyAccidInit()" :disabled='disabledSave'>
                  <Icon type="ios-checkmark icon" />网易账号初始化
                </Button>
            </div>
        </Form>
    </div>
</template>
<script>
    import api from "@/api/commonApi";
    export default {
        data() {
            return {
                formItem: {
                    value1: '',
                    value2: '',
                    value3: '',
                    value6: false,
                },
                status:null,
                historylist:[],
                disabledSave: false
            }
        },
        created() {
            let breadList = [
                { path: "/index", title: "首页" },
                {
                    path: "",
                    title: "系统运营参数配置"
                },
                {
                    path: "/index/configuration/timelimit/index",
                    title: "平台时限配置"
                }
            ];
            this.$emit("changeBreadList", breadList);
        },
        mounted(){
            //限时/规则/密码配置管理-列表
            this.$axios.post(api.findConfigList,{}).then(res => {
                if (res.data.code === 1) {
                    this.historylist = res.data.object
                    if(this.historylist.length<=0){
                        this.status = 0
                    }else{
                        this.status = 1
                        this.formItem.value1 = this.historylist[2].configValue
                        this.formItem.value2 = this.historylist[3].configValue
                        this.formItem.value3 = this.historylist[4].configValue
                    }
                } else {
                    this.$Message.error('请求异常');
                    return false;
                }
            }).catch(() => {
                this.loading = false;
            });
        },
        methods:{
            //限时配置管理-保存
            submit(e){
                this.disabledSave = true
                let params;
                if(this.status == 0){
                    params = [
                        {
                            "id": '0',
                            "configKey": "Audit_Time",
                            "configName": "药师审核时限",
                            "configExplain": "如果药师接收处方后，超过此时限还没有审核完处方，则处方自动回到处方池",
                            "configValue": this.formItem.value1.toString(),
                        },
                        {
                            "id": '0',
                            "configKey": "Pay_Time",
                            "configName": "患者支付时限",
                            "configExplain": "处方审核通过后，如果患者超过此时限还没有支付，则处方自动失效",
                            "configValue": this.formItem.value2.toString(),
                        },
                        {
                            "id": '0',
                            "configKey": "Good_Time",
                            "configName": "患者确认收货时限",
                            "configExplain": "药品送达后，如果患者超过此时限还没有点击【确认收货】，则处方订单自动更新为完成状态",
                            "configValue": this.formItem.value3.toString(),
                        },
                    ]
                }else{
                    params = [
                        {
                            "id": this.historylist[0].id,
                            "configKey": "Audit_Time",
                            "configName": "药师审核时限",
                            "configExplain": "如果药师接收处方后，超过此时限还没有审核完处方，则处方自动回到处方池",
                            "configValue": this.formItem.value1
                        },
                        {
                            "id": this.historylist[1].id,
                            "configKey": "Pay_Time",
                            "configName": "患者支付时限",
                            "configExplain": "处方审核通过后，如果患者超过此时限还没有支付，则处方自动失效",
                            "configValue": this.formItem.value2
                        },
                        {
                            "id": this.historylist[2].id,
                            "configKey": "Good_Time",
                            "configName": "患者确认收货时限",
                            "configExplain": "药品送达后，如果患者超过此时限还没有点击【确认收货】，则处方订单自动更新为完成状态",
                            "configValue": this.formItem.value3
                        },
                    ]
                }
                this.$axios.post(api.createConfigList,params).then(res => {
                    if (res.data.code === 1) {
                        this.$Message.success('平台时限配置成功');
                        setTimeout(() => {
                            this.disabledSave = false
                        }, 1000);
                    } else {
                        this.$Message.error('平台时限配置失败，请稍后重试');
                        this.disabledSave = false
                        return false;
                    }
                }).catch(() => {
                    this.loading = false;
                });
            },
            wyAccidInit(){
                this.$axios.post(api.wyAccidInit,{}).then(res => {
                    if (res.data.code === 1) {
                        this.$Message.success('网易账号初始化成功');
                    } else {
                        this.$Message.error('网易账号初始化失败，请稍后重试');
                        return false;
                    }
                }).catch(() => {
                    this.loading = false;
                });
            }
        },
    }
</script>
<style scoped lang="less">
    .timeindex {
        width: 100%;
        min-width: 1200px;
        min-height: 600px;
        padding: 20px 0px 10px 0px;
        margin: 0 auto;
        background: #fff;
        .input{
            width: 200px;
        }
        small{
            color: #333;
            font-size: 12px;
            line-height: 35px;
            margin-left: -15px;
        }
        .span{
            color:#FF9966;
            display: inline-block;
            height: 50px;
            margin-bottom: 20px;
            font-size: 12px;
            line-height: 25px;
        }
        .tit {
            margin:10px 0;
            font-weight:bold;
            text-align:center;
        }
        .main{
            width: 98%;
            display: flex;
            flex-direction: column;
            margin: 10px auto;
            border: 1px solid #f0f0f0;
            box-shadow: 0 4px 3px #ebedf8;
            border-radius: 5px;
            margin-bottom: 20px;
            .title {
                font-size: 20px;
                padding-left: 15px;
                margin-bottom: 20px;
                color: #333;
                height: 40px;
                line-height: 40px;
                background: #ebedf8;
            }
            .box{
                padding: 0 30px;
            }
        }
        .buttonbox {
            width: 100%;
            text-align: center;
            .icon {
                margin-right: 5px;
            }
        }
    }
</style>
